package com.dyh.quickdemozwei.controller;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.dyh.quickdemozwei.controller.http.HttpBody;
import com.dyh.quickdemozwei.controller.http.HttpContext;
import com.dyh.quickdemozwei.controller.http.HttpUtils;
import com.dyh.quickdemozwei.controller.http.PlainHttpBody;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;

@RequestMapping("/albb")
@Controller
@Slf4j
public class AlbbController {


    @RequestMapping("/route")
    @ResponseBody //不加这个404
    Object route(HttpServletRequest httpServletRequest) {
        log.info("表单参数={}", JSON.toJSONString(httpServletRequest.getParameterMap()));

        HttpBody httpbody = new PlainHttpBody(JSON.toJSONString(httpServletRequest.getParameterMap()));
        HttpContext context = new HttpContext();
        context.setContentType("application/json");
        String resultStr = HttpUtils.post("http://localhost:1919/albb/system", context, httpbody);

        log.info("resultStr={}",resultStr);
        return new JSONObject();
    }



    @RequestMapping("/system")
    @ResponseBody
    Object system(@RequestBody String messageStr) {

        return new JSONObject();
    }

}
